package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.example.framework.Contacts;
import com.example.objects.ContactObject;

public class ContactCreationTests extends TestBase {

	@Test(dataProvider = "contactsFromFile", dataProviderClass = ContactDataGenerator.class)
	public void testValidContactCanBeCreated(ContactObject validContact) {
		Contacts oldList = app.getContactHelper().getContacts();
		app.getContactHelper().createContact(validContact);
		Contacts newList = app.getContactHelper().getContacts();
		assertThat(newList, equalTo(oldList.withAdded(validContact)));		
	}
	
	@AfterMethod
	public void testUiAndDbConformWithDb() {
		if (app.getProperty("ui.check") != null) {
			Contacts modelList = app.getContactHelper().getContacts();
			Contacts uiList = app.getContactHelper().getUiContacts();
			assertThat(uiList, equalTo(modelList));
		}
		if (app.getProperty("db.check") != null) {
			Contacts modelList = app.getContactHelper().getContacts();
			Contacts dbList = app.getHibernateHelper().getContacts();
			assertThat(dbList, equalTo(modelList));
		}
	}
	
}
